package com.wims.client;

import java.util.ArrayList;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class WIMS_GWT implements EntryPoint, PageHolder {
	/**
	 * Create a remote service proxy to talk to the server-side service. TODO
	 * Change service as needed
	 */
	private final GreetingServiceAsync greetingService = GWT
			.create(GreetingService.class);

	/** All pages in the application hooked up to the main HTML */
	private ArrayList<PageWrapper> pages = new ArrayList<PageWrapper>();

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		// Create and hook up pages
		pages.add(new LoginPage(this, greetingService));
		pages.add(new ThreeColumnPage(this));

		// Hide all screens but login
		setActivePage(LoginPage.pageName);
	}

	public void showMessage(String message) {
		// Can do something prettier. See DialogBox code from examples
		Window.alert(message);
	}

	@Override
	public void setActivePage(String pageName) {
		for (PageWrapper pw : pages) {
			String pn = pw.getPageName();
			RootPanel.get(pn).setVisible(pageName.equals(pn));
		}
	}

	@Override
	public PageWrapper findPage(String pageName) {
		for (PageWrapper pw : pages) {
			if (pageName.equals(pw.getPageName()))
				return pw;
		}
		return null;
	}
}
